#!/usr/bin/php -q
<?PHP
	$file = '/home/dmdirc/nightly.log';
	
	$SVN = getenv('DMDIRC_SVN');
	
	if (getenv('DMDIRC_INSTALLERFAILURE')) {
		$title = 'Nightly Installer Build Failure';
	} else {
		$title = 'Nightly Build Failure';
	}
	
	if ($SVN === false) {
		exit(1);
	} else if (!file_exists($file) || ($data = @file_get_contents($file)) === false) {
		echo "Unable to open $file\n";
		exit(1);
	}
	
	file_get_contents('http://www.dmdirc.com/error.php' . $requestdata);
	
	# $sock = @fsockopen('www.dmdirc.com', 80, $errno, $errstr, 10);
	$sock = false;
	echo $data;
	if ($sock) {
		$headers = array();
		$headers[] = 'POST /error.php HTTP/1.0';
		$headers[] = 'Host: www.dmdirc.com';
		$headers[] = 'User-Agent: Nightly Failure Reporter';
		
		$postline = 'trace='.urlencode($data);
		$postline .= '&noformat';
		$postline .= '&version=SVN('.$SVN.')';
		$postline .= '&message='.$title.' ('.$SVN.')';
		
		$headers[] = 'Content-Type: application/x-www-form-urlencoded';
		$headers[] = 'Content-Length: '.strlen($postline);
		$headers[] = '';
		$headers[] = $postline;
		
		$headers[] = "\n";
		$data = '';
		fwrite($sock, implode($headers, "\n"));
		while (!feof($sock)) { @fgets($sock, 4096); }
		fclose($sock);
	}
?>
